{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## %格式化\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'name: 张三, age:  22, male: True'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"name: %s, age: %3d, male: %s\" % (\"张三\", 22, True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'5:5, 5.5:5, True:1'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"5:%d, 5.5:%d, True:%d\" % (5, 5.5, True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "| 输出为               | 格式 | 案例       |\n",
    "| -------------------- | ---- | ---------- |\n",
    "| 字符串               | %s   | `'%s' % a` |\n",
    "| 10 机制整数          | %d   | `'%s' % a` |\n",
    "| 16 进制整数          | %x   | `'%s' % a` |\n",
    "| 8 进制整数           | %o   | `'%s' % a` |\n",
    "| 十进制浮点数         | %f   | `'%s' % a` |\n",
    "| 指数型浮点数         | %e   | `'%s' % a` |\n",
    "| 十进制或指数型浮点数 | %g   | `'%s' % a` |\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`%[+-][m][.n]s`\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
